package org.thread.test03.way02;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author CSY
 * @date 2025 - 03 - 10
 */
public class MainTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //第二：创建实现Callable接口的对象
        MyCallable mc =  new MyCallable();
        //第三：创建FutureTask对象,并设置Callable对象
        FutureTask<Integer> ft = new FutureTask<>(mc);
        //第四：创建线程对象
        Thread t = new Thread(ft);
        //第五：启动线程
        t.start();

        Thread.sleep(3000);
        ft.cancel(true);
        //第六：获取结果（主线程阻塞，同步等待 task 执行完毕的结果）
        Integer i = ft.get();

        System.out.println(i);

    }
}
